home *** CD-ROM | disk | FTP | other *** search
/ Java Certification Exam Guide / McGrawwHill-JavaCertificationExamGuide.iso / pc / Web Links and Code / ans / chap11 / exer1101 / NewFile.java
Encoding:
Java Source  |  1997-04-20  |  496 b   |  21 lines

  1. import java.io.*;
  2.  
  3. class NewFile {
  4.    public static void main(String[] args) {
  5.       if (args.length != 1) {
  6.          System.out.println("Supply a file name.");
  7.          System.exit(1);
  8.       }
  9.  
  10.       try {
  11.          File f = new File(args[0]);
  12.          if (f.exists())
  13.             System.out.println(args[0] + " already exists.");
  14.          else
  15.             new FileOutputStream(f);
  16.       } catch (IOException io) {
  17.          System.out.println(io.getMessage());
  18.       }
  19.    }
  20. }
  21.